package com.yanfei.zero.apis;

import java.io.IOException;
import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yanfei.zero.application.handler.perms.ICmResourceService;
import com.yanfei.zero.application.handler.secret.IgnoreDecrypt;
import com.yanfei.zero.infrastructure.cloud.ServiceProviderClient;

import cn.hutool.json.JSONArray;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
@Tag(name="权限相关")
@RestController
public class PermsController {
	@Resource
	private ICmResourceService cmResourceService;
	@Resource
	private ServiceProviderClient serviceProviderClient;
	
	@Operation(summary = "查询树形结构")
    @GetMapping(path = "getTree")
    public Object getTree(String id, String content) {
		return serviceProviderClient.g();
//        return cmResourceService.getTree();
    }
	
	
	@Operation(summary = "算法得到结构")
    @GetMapping(path = "getTree2")
    public Object getTree2() {
        return cmResourceService.getTree2();
    }
	
	@Operation(summary = "创建站点")
	@RequestMapping(path = "/sitemaps")
	public Object createSitemap(HttpServletRequest req) throws IOException {
        // 获取请求的输入流
		String method = req.getMethod();
		String type = req.getContentType();
        StringBuilder requestBody = new StringBuilder();
        String line;
        while ((line = req.getReader().readLine()) != null) {
            requestBody.append(line);
        }
		return "succes";
	}
	@Operation(summary = "保存数据")
	@RequestMapping(path = "api/sync")
	@IgnoreDecrypt
	public Object saveSitemap1(@RequestBody JSONArray json) {
        // 获取请求的输入流
//		String method = req.getMethod();
//		String type = req.getContentType();
//        StringBuilder requestBody = new StringBuilder();
//        String line;
//        while ((line = req.getReader().readLine()) != null) {
//            requestBody.append(line);
//        }
		return "succes";
	}
}
